package com.yxw.live_vod_backend_boot.controller;

import com.yxw.live_vod_backend_boot.dto.CategorySpecificationAddDTO;
import com.yxw.live_vod_backend_boot.dto.CategorySpecificationQueryDTO;
import com.yxw.live_vod_backend_boot.dto.CategorySpecificationUpdateDTO;
import com.yxw.live_vod_backend_boot.service.CategorySpecificationService;
import com.yxw.live_vod_backend_boot.vo.CategorySpecificationVO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类目规格管理 Controller控制层
 *
 * @author xiexuxin
 * @date 2023-12-06
 */
@RestController
@Api(value = "类目规格管理", tags = "类目规格管理")
@Slf4j
@RequestMapping("/api/category_specification")
public class CategorySpecificationController {

    @Autowired
    private CategorySpecificationService specificationService;

    @ApiOperation("添加类目规格")
    @PostMapping("add_specification")
    public BaseResult addSpecification(@RequestBody @Validated CategorySpecificationAddDTO addDTO) {
        specificationService.addSpecification(addDTO);
        return BaseResult.doSuccess(null, "添加成功");
    }

    @ApiOperation("修改类目规格")
    @PostMapping("update_specification")
    public BaseResult updateSpecification(@RequestBody @Validated CategorySpecificationUpdateDTO updateDTO) {
        specificationService.updateSpecification(updateDTO);
        return BaseResult.doSuccess(null, "修改成功");
    }

    @ApiOperation("获取类目规格列表")
    @PostMapping("get_specification_list")
    public BaseResult<PageVO<CategorySpecificationVO>> getSpecificationList(@RequestBody @Validated CategorySpecificationQueryDTO queryDTO) {
        PageVO<CategorySpecificationVO> pageVO = specificationService.getSpecificationList(queryDTO);
        return ResultHelper.fillWithSuccess(pageVO);
    }

    @ApiOperation("获取类目规格详情")
    @PostMapping("get_specification_by_id")
    public BaseResult getSpecificationById(@RequestParam("specificationId") String specificationId) {
        CategorySpecificationVO specificationVO = specificationService.getSpecificationById(specificationId);
        return BaseResult.doSuccess(specificationVO,"查询成功");
    }

    @ApiOperation("根据类目Id获取规格列表")
    @PostMapping("get_specification_list_by_category_id")
    public BaseResult getSpecificationListByCategoryId(@RequestParam("categoryId") String categoryId) {
        List<CategorySpecificationVO> list = specificationService.getSpecificationListByCategoryId(categoryId);
        return BaseResult.doSuccess(list,"查询成功");
    }

}
